package cn.edu.scau.cmi.linyiqu.singleton;

import java.util.ArrayList;

public class Marshal {
    private static int position = 10;
    private static int count = 10;
    private static ArrayList<String> names = new ArrayList<String>();
    private static ArrayList<Marshal> marshals = new ArrayList<Marshal>();
    private String name;

    private Marshal(String name){
        this.name = name;
    }

    public static void getInstance(String name){
        if(count>0 && !name.equals(null) )
            if(!names.contains(name)){
                names.add(name);
                Marshal marshal = new Marshal(name);
                marshals.add(marshal);
                count--;
            }
    }

    public String getName(){
        return name;
    }

    public static String output() {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("十大元帅\n");
        for(int index=0;index<position-count;index++){
            stringBuffer.append(marshals.get(index).getName()+"  "+marshals.get(index).toString()+"\n");
        }
        return stringBuffer.toString();
    }
}
